<?php

use common\helpers\Url;
use yii\grid\GridView;
use common\helpers\Html;

$this->title = '流程状态';
$this->params['breadcrumbs'][] = ['label' => $this->title];

?>

<div class="row">
    <div class="col-sm-12">
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li><a href="<?= Url::to(['index']) ?>">已安装的流程</a></li>
                <li class="active"><a href="<?= Url::to(['all']) ?>">所有流程</a></li>

            </ul>
            <div class="tab-content">
                <div class="active tab-pane">
                    <?= GridView::widget([
                        'dataProvider' => $dataProvider,
//                        'filterModel' => $searchModel,
                        //重新定义分页样式
                        'tableOptions' => [
                            'class' => 'table table-hover rf-table',
                            'fixedNumber' => 1,
//                            'fixedRightNumber' => 1,
                        ],
                        'columns' => [
                            [
                                'attribute' => 'title',
                                'label' => '工作流名',
                            ],
                            [
                                'attribute' => 'id',
                                'label' => '工作流ID',
                                'value' => function ($model) {
                                    $workflow_id = \common\helpers\StringHelper::cut('/office/approve/', '/index', $model->url);
                                    return $workflow_id;
                                },
                            ],
                            [
                                'attribute' => '初始状态',
                                'value' => function ($model) {
                                    return 'apply';
                                },
                            ],
                            [
                                'headerOptions' => ['width' => '180'],
                                'header' => "操作",
                                'class' => 'yii\grid\ActionColumn',
                                'template' => '{install}',
                                'buttons' => [
                                    'install' => function ($url, $model, $key) {
                                        $workflow_id = \common\helpers\StringHelper::cut('/office/approve/', '/index', $model->url);
                                        $workflow = \addons\Flow\common\models\Workflow::find()->where(['merchant_id' => Yii::$app->user->identity->merchant_id, 'id' => $workflow_id])->one();
                                        if ($workflow)
                                            return Html::edit(['workflow/install'], '已安装', [
                                                'class' => 'btn btn-default btn-sm',
                                            ]);
                                        else
                                            return Html::edit(['workflow/install', 'id' => $workflow_id, 'title' => $model->title], '点击安装', [
                                                'class' => 'btn btn-success btn-sm',
                                            ]);
                                    },
                                ],
                            ],
                        ],
                    ]); ?>
                </div>
            </div>
        </div>
    </div>
</div>